<?php

namespace app\model;

use think\Model;

class User extends Model
{
    //protected $name = 'User';
    protected $table = 'site_user';
    protected $connection = 'mysql';
    protected $schema = [
        'id' => 'int',
        'email' => 'string',
        'password' => 'string',
        'token' => 'string',
        'ip' => 'string',
        'time' => 'datetime',
        'risk' => 'int',
        'money' => 'float',
        'status' => 'string',
        'name' => 'string',
        'img' => 'string',
        'bcm_id' => 'int'

    ];
    static public function get($item = "", $pw = "")
    {
        if ($item == "") {
            return array('name' => "未登录", 'img' => 'https://creation.codemao.cn/716/appcraft/IMAGE_U53LlVovA_1693015896678.png', 'email' => '');
        }

        $user = User::where('email', $item)->find();

        if ($pw == $user->password) {
            return get_object_vars($user);
        } else {
            return array('name' => "未登录", 'img' => 'https://creation.codemao.cn/716/appcraft/IMAGE_U53LlVovA_1693015896678.png', 'email' => '');
        }
    }

    static public function hasName($name)
    {
        return count(self::where('name', $name)->select()->toArray()) != 0;
    }
}
